﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sofire.Data;

namespace SofireXSqlEntityGenerator.Core
{
    public class OracleGenerator : SqlGeneratorBase
    {
        public OracleGenerator(QueryEngineBase engine) : base(engine) { }

        public override TableResult GetUserTables()
        {
            return this.Engine.ExecuteTable("SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME");
        }

        public override TableResult GetUserViews()
        {
            return this.Engine.ExecuteTable("SELECT VIEW_NAME FROM USER_VIEWS ORDER BY VIEW_NAME");
        }

        public override TableResult GetTableColumns(string tableName)
        {
            return this.Engine.ExecuteTable(@"
SELECT a.COLUMN_NAME AS FiledName
,CASE WHEN a.NULLABLE='Y' THEN 1 ELSE 0 END AS IsNullable
,b.COMMENTS          AS FieldComments
FROM  USER_TAB_COLUMNS a,USER_COL_COMMENTS b WHERE a.COLUMN_NAME=b.COLUMN_NAME 
AND    a.TABLE_NAME = b.TABLE_NAME AND a.TABLE_NAME=:tableName", "tableName", tableName);
        }
    }
}
